package com.per.mybootall.moreDatasourse;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.per.mybootall.moreDatasourse.mapper.MoreDatasourseMapper;
import com.per.mybootall.moreDatasourse.po.MoreDatesoursePo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


    /*
    * 苞米豆多数据源进行操作的demo
    *       @DS(value="")  通过该注解进行多数据源的动态切换
    *
    * */
@RestController
public class MoreDatesourseController {

        @Resource
        MoreDatasourseMapper moreDatasourseMapper;

    /*
     * 测试：http://localhost:8080/find1
     * 结果：[{"id":1,"username":"moreDatesourseTest1","password":"moreDatesourseTest1"}]
     * */
    //通过@DS注解指定在配置文件中配置的多数据源
        @GetMapping("find1")
        @ResponseBody
        public List<MoreDatesoursePo> find(){
            List<MoreDatesoursePo> list =moreDatasourseMapper.selectByPrimaryKey();
            return  list;
        }

    /*
     * 测试：http://localhost:8080/find2
     * 结果：[{"id":1,"username":"moreDatesourseTest2","password":"moreDatesourseTest2"}]
     * */
        //通过@DS注解指定在配置文件中配置的多数据源
        @DS(value = "slave_1")
        @GetMapping("find2")
        @ResponseBody
        public List<MoreDatesoursePo> find1(){
            List<MoreDatesoursePo> list = moreDatasourseMapper.selectByPrimaryKey();
            return  list;
        }


        /*
        * 测试：http://localhost:8080/find3
        * 结果：[{"id":1,"username":"moreDatesourseTest3","password":"moreDatesourseTest3"}]
        * */
        //通过@DS注解指定在配置文件中配置的多数据源
        @DS(value = "slave_2")
        @GetMapping("find3")
        @ResponseBody
        public List<MoreDatesoursePo> find2(){
            List<MoreDatesoursePo> list = moreDatasourseMapper.selectByPrimaryKey();
            return  list;
        }

}
